home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / progs / demos / glutmech / glutmech.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  38KB  |  1,803 lines

  1.  
  2. /**
  3. * program    : glutmech V1.1
  4. * author    : Simon Parkinson-Bates.
  5. * E-mail    : sapb@yallara.cs.rmit.edu.au
  6. * Copyright Simon Parkinson-Bates.
  7. * "source if freely avaliable to anyone to copy as long as they
  8. *  acknowledge me in their work."
  9. *
  10. * Funtional features 
  11. * ------------------
  12. * * online menu system avaliable by pressing left mouse button
  13. * * online cascading help system avaliable, providing information on
  14. *    the several  key strokes and what they do.
  15. * * animation sequence coded which makes the mech walk through an
  16. *    environment.  Shadows will soon be added to make it look
  17. *    more realistic.
  18. * * menu control to view mech in wireframe or sold mode.
  19. * * various key strokes avaliable to control idependently the mechs
  20. *    many joints.
  21. * * various key strokes avaliable to view mech and environment from 
  22. *    different angles
  23. * * various key strokes avaliable to alter positioning of the single
  24. *    light source.
  25. *
  26. *
  27. * Program features
  28. * ----------------
  29. * * uses double buffering
  30. * * uses display lists
  31. * * uses glut to manage windows, callbacks, and online menu.
  32. * * uses glpolygonfill() to maintain colors in wireframe and solid
  33. *    mode.
  34. *
  35. **/
  36.  
  37. /* start of compilation conditions */
  38. #define SPHERE
  39. #define COLOR
  40. #define LIGHT
  41. #define TORSO
  42. #define HIP
  43. #define SHOULDER
  44. #define UPPER_ARM
  45. #define LOWER_ARM
  46. #define ROCKET_POD
  47. #define UPPER_LEG
  48. #define LOWER_LEG
  49. #define NO_NORM
  50. #define ANIMATION
  51. #define DRAW_MECH
  52. #define DRAW_ENVIRO
  53. #define MOVE_LIGHT
  54. /* end of compilation conditions */
  55.  
  56. /* start various header files needed */
  57. #include <GL/gl.h>
  58. #include <GL/glu.h>
  59. #include <stdlib.h>
  60. #include <math.h>
  61. #define GLUT
  62. #define GLUT_KEY
  63. #define GLUT_SPEC
  64. #include <GL/glut.h>
  65. /* end of header files */
  66.  
  67. /* start of display list definitions */
  68. #define SOLID_MECH_TORSO           1
  69. #define SOLID_MECH_HIP          2
  70. #define SOLID_MECH_SHOULDER     3
  71. #define SOLID_MECH_UPPER_ARM    4
  72. #define SOLID_MECH_FOREARM    5
  73. #define SOLID_MECH_UPPER_LEG       6
  74. #define SOLID_MECH_FOOT            7
  75. #define SOLID_MECH_ROCKET          8
  76. #define SOLID_MECH_VULCAN    9
  77. #define SOLID_ENVIRO        10
  78. /* end of display list definitions */
  79.  
  80. /* start of motion rate variables */
  81. #define ANKLE_RATE    3
  82. #define HEEL_RATE    3
  83. #define ROTATE_RATE    10
  84. #define TILT_RATE    10
  85. #define ELBOW_RATE    2
  86. #define SHOULDER_RATE    5
  87. #define LAT_RATE    5
  88. #define CANNON_RATE    40
  89. #define UPPER_LEG_RATE    3
  90. #define UPPER_LEG_RATE_GROIN 10
  91. #define LIGHT_TURN_RATE    10
  92. #define VIEW_TURN_RATE    10
  93. /* end of motion rate variables */
  94.  
  95. /* start of motion  variables */
  96. #ifndef PI
  97. #define PI 3.141592654
  98. #endif
  99.  
  100. char leg = 0;
  101.  
  102. int shoulder1 = 0, shoulder2 = 0, shoulder3 = 0, shoulder4 = 0, lat1 = 20, lat2 = 20,
  103.   elbow1 = 0, elbow2 = 0, pivot = 0, tilt = 10, ankle1 = 0, ankle2 = 0, heel1 = 0,
  104.   heel2 = 0, hip11 = 0, hip12 = 10, hip21 = 0, hip22 = 10, fire = 0, solid_part = 0,
  105.   anim = 0, turn = 0, turn1 = 0, lightturn = 0, lightturn1 = 0;
  106.  
  107. float elevation = 0.0, distance = 0.0, frame = 3.0
  108.  /* foot1v[] = {} foot2v[] = {} */ ;
  109.  
  110. /* end of motion variables */
  111.  
  112. /* start of material definitions */
  113. #ifdef LIGHT
  114. GLfloat mat_specular[] =
  115. {0.628281, 0.555802, 0.366065, 1.0};
  116. GLfloat mat_ambient[] =
  117. {0.24725, 0.1995, 0.0745, 1.0};
  118. GLfloat mat_diffuse[] =
  119. {0.75164, 0.60648, 0.22648, 1.0};
  120. GLfloat mat_shininess[] =
  121. {128.0 * 0.4};
  122.  
  123. GLfloat mat_specular2[] =
  124. {0.508273, 0.508273, 0.508373};
  125. GLfloat mat_ambient2[] =
  126. {0.19225, 0.19225, 0.19225};
  127. GLfloat mat_diffuse2[] =
  128. {0.50754, 0.50754, 0.50754};
  129. GLfloat mat_shininess2[] =
  130. {128.0 * 0.6};
  131.  
  132. GLfloat mat_specular3[] =
  133. {0.296648, 0.296648, 0.296648};
  134. GLfloat mat_ambient3[] =
  135. {0.25, 0.20725, 0.20725};
  136. GLfloat mat_diffuse3[] =
  137. {1, 0.829, 0.829};
  138. GLfloat mat_shininess3[] =
  139. {128.0 * 0.088};
  140.  
  141. GLfloat mat_specular4[] =
  142. {0.633, 0.727811, 0.633};
  143. GLfloat mat_ambient4[] =
  144. {0.0215, 0.1745, 0.0215};
  145. GLfloat mat_diffuse4[] =
  146. {0.07568, 0.61424, 0.07568};
  147. GLfloat mat_shininess4[] =
  148. {128 * 0.6};
  149.  
  150. GLfloat mat_specular5[] =
  151. {0.60, 0.60, 0.50};
  152. GLfloat mat_ambient5[] =
  153. {0.0, 0.0, 0.0};
  154. GLfloat mat_diffuse5[] =
  155. {0.5, 0.5, 0.0};
  156. GLfloat mat_shininess5[] =
  157. {128.0 * 0.25};
  158.  
  159. #endif
  160. /* end of material definitions */
  161.  
  162. /* start of the body motion functions */
  163. void
  164. Heel1Add(void)
  165. {
  166.   heel1 = (heel1 + HEEL_RATE) % 360;
  167. }
  168.  
  169. void
  170. Heel1Subtract(void)
  171. {
  172.   heel1 = (heel1 - HEEL_RATE) % 360;
  173. }
  174.  
  175. void
  176. Heel2Add(void)
  177. {
  178.   heel2 = (heel2 + HEEL_RATE) % 360;
  179. }
  180.  
  181. void
  182. Heel2Subtract(void)
  183. {
  184.   heel2 = (heel2 - HEEL_RATE) % 360;
  185. }
  186.  
  187. void
  188. Ankle1Add(void)
  189. {
  190.   ankle1 = (ankle1 + ANKLE_RATE) % 360;
  191. }
  192.  
  193. void
  194. Ankle1Subtract(void)
  195. {
  196.   ankle1 = (ankle1 - ANKLE_RATE) % 360;
  197. }
  198.  
  199. void
  200. Ankle2Add(void)
  201. {
  202.   ankle2 = (ankle2 + ANKLE_RATE) % 360;
  203. }
  204.  
  205. void
  206. Ankle2Subtract(void)
  207. {
  208.   ankle2 = (ankle2 - ANKLE_RATE) % 360;
  209. }
  210.  
  211. void
  212. RotateAdd(void)
  213. {
  214.   pivot = (pivot + ROTATE_RATE) % 360;
  215. }
  216.  
  217. void
  218. RotateSubtract(void)
  219. {
  220.   pivot = (pivot - ROTATE_RATE) % 360;
  221. }
  222.  
  223. void
  224. MechTiltSubtract(void)
  225. {
  226.   tilt = (tilt - TILT_RATE) % 360;
  227. }
  228.  
  229. void
  230. MechTiltAdd(void)
  231. {
  232.   tilt = (tilt + TILT_RATE) % 360;
  233. }
  234.  
  235. void
  236. elbow1Add(void)
  237. {
  238.   elbow1 = (elbow1 + ELBOW_RATE) % 360;
  239. }
  240.  
  241. void
  242. elbow1Subtract(void)
  243. {
  244.   elbow1 = (elbow1 - ELBOW_RATE) % 360;
  245. }
  246.  
  247. void
  248. elbow2Add(void)
  249. {
  250.   elbow2 = (elbow2 + ELBOW_RATE) % 360;
  251. }
  252.  
  253. void
  254. elbow2Subtract(void)
  255. {
  256.   elbow2 = (elbow2 - ELBOW_RATE) % 360;
  257. }
  258.  
  259. void
  260. shoulder1Add(void)
  261. {
  262.   shoulder1 = (shoulder1 + SHOULDER_RATE) % 360;
  263. }
  264.  
  265. void
  266. shoulder1Subtract(void)
  267. {
  268.   shoulder1 = (shoulder1 - SHOULDER_RATE) % 360;
  269. }
  270.  
  271. void
  272. shoulder2Add(void)
  273. {
  274.   shoulder2 = (shoulder2 + SHOULDER_RATE) % 360;
  275. }
  276.  
  277. void
  278. shoulder2Subtract(void)
  279. {
  280.   shoulder2 = (shoulder2 - SHOULDER_RATE) % 360;
  281. }
  282.  
  283. void
  284. shoulder3Add(void)
  285. {
  286.   shoulder3 = (shoulder3 + SHOULDER_RATE) % 360;
  287. }
  288.  
  289. void
  290. shoulder3Subtract(void)
  291. {
  292.   shoulder3 = (shoulder3 - SHOULDER_RATE) % 360;
  293. }
  294.  
  295. void
  296. shoulder4Add(void)
  297. {
  298.   shoulder4 = (shoulder4 + SHOULDER_RATE) % 360;
  299. }
  300.  
  301. void
  302. shoulder4Subtract(void)
  303. {
  304.   shoulder4 = (shoulder4 - SHOULDER_RATE) % 360;
  305. }
  306.  
  307. void
  308. lat1Raise(void)
  309. {
  310.   lat1 = (lat1 + LAT_RATE) % 360;
  311. }
  312.  
  313. void
  314. lat1Lower(void)
  315. {
  316.   lat1 = (lat1 - LAT_RATE) % 360;
  317. }
  318.  
  319. void
  320. lat2Raise(void)
  321. {
  322.   lat2 = (lat2 + LAT_RATE) % 360;
  323. }
  324.  
  325. void
  326. lat2Lower(void)
  327. {
  328.   lat2 = (lat2 - LAT_RATE) % 360;
  329. }
  330.  
  331. void
  332. FireCannon(void)
  333. {
  334.   fire = (fire + CANNON_RATE) % 360;
  335. }
  336.  
  337. void
  338. RaiseLeg1Forward(void)
  339. {
  340.   hip11 = (hip11 + UPPER_LEG_RATE) % 360;
  341. }
  342.  
  343. void
  344. LowerLeg1Backwards(void)
  345. {
  346.   hip11 = (hip11 - UPPER_LEG_RATE) % 360;
  347. }
  348.  
  349. void
  350. RaiseLeg1Outwards(void)
  351. {
  352.   hip12 = (hip12 + UPPER_LEG_RATE_GROIN) % 360;
  353. }
  354.  
  355. void
  356. LowerLeg1Inwards(void)
  357. {
  358.   hip12 = (hip12 - UPPER_LEG_RATE_GROIN) % 360;
  359. }
  360.  
  361. void
  362. RaiseLeg2Forward(void)
  363. {
  364.   hip21 = (hip21 + UPPER_LEG_RATE) % 360;
  365. }
  366.  
  367. void
  368. LowerLeg2Backwards(void)
  369. {
  370.   hip21 = (hip21 - UPPER_LEG_RATE) % 360;
  371. }
  372.  
  373. void
  374. RaiseLeg2Outwards(void)
  375. {
  376.   hip22 = (hip22 + UPPER_LEG_RATE_GROIN) % 360;
  377. }
  378.  
  379. void
  380. LowerLeg2Inwards(void)
  381. {
  382.   hip22 = (hip22 - UPPER_LEG_RATE_GROIN) % 360;
  383. }
  384.  
  385. /* end of body motion functions */
  386.  
  387. /* start of light source position functions */
  388. void
  389. TurnRight(void)
  390. {
  391.   turn = (turn - VIEW_TURN_RATE) % 360;
  392. }
  393.  
  394. void
  395. TurnLeft(void)
  396. {
  397.   turn = (turn + VIEW_TURN_RATE) % 360;
  398. }
  399.  
  400. void
  401. TurnForwards(void)
  402. {
  403.   turn1 = (turn1 - VIEW_TURN_RATE) % 360;
  404. }
  405.  
  406. void
  407. TurnBackwards(void)
  408. {
  409.   turn1 = (turn1 + VIEW_TURN_RATE) % 360;
  410. }
  411.  
  412. void
  413. LightTurnRight(void)
  414. {
  415.   lightturn = (lightturn + LIGHT_TURN_RATE) % 360;
  416. }
  417.  
  418. void
  419. LightTurnLeft(void)
  420. {
  421.   lightturn = (lightturn - LIGHT_TURN_RATE) % 360;
  422. }
  423.  
  424. void
  425. LightForwards(void)
  426. {
  427.   lightturn1 = (lightturn1 + LIGHT_TURN_RATE) % 360;
  428. }
  429.  
  430. void
  431. LightBackwards(void)
  432. {
  433.   lightturn1 = (lightturn1 - LIGHT_TURN_RATE) % 360;
  434. }
  435.  
  436. /* end of light source position functions */
  437.  
  438. /* start of geometric shape functions */
  439. void
  440. Box(float width, float height, float depth, char solid)
  441. {
  442.   char i, j = 0;
  443.   float x = width / 2.0, y = height / 2.0, z = depth / 2.0;
  444.  
  445.   for (i = 0; i < 4; i++) {
  446.     glRotatef(90.0, 0.0, 0.0, 1.0);
  447.     if (j) {
  448.       if (!solid)
  449.         glBegin(GL_LINE_LOOP);
  450.       else
  451.         glBegin(GL_QUADS);
  452.       glNormal3f(-1.0, 0.0, 0.0);
  453.       glVertex3f(-x, y, z);
  454.       glVertex3f(-x, -y, z);
  455.       glVertex3f(-x, -y, -z);
  456.       glVertex3f(-x, y, -z);
  457.       glEnd();
  458.       if (solid)
  459.         glBegin(GL_TRIANGLES);
  460.       glNormal3f(0.0, 0.0, 1.0);
  461.       glVertex3f(0.0, 0.0, z);
  462.       glVertex3f(-x, y, z);
  463.       glVertex3f(-x, -y, z);
  464.       glNormal3f(0.0, 0.0, -1.0);
  465.       glVertex3f(0.0, 0.0, -z);
  466.       glVertex3f(-x, -y, -z);
  467.       glVertex3f(-x, y, -z);
  468.       glEnd();
  469.       j = 0;
  470.     } else {
  471.       if (!solid)
  472.         glBegin(GL_LINE_LOOP);
  473.       else
  474.         glBegin(GL_QUADS);
  475.       glNormal3f(-1.0, 0.0, 0.0);
  476.       glVertex3f(-y, x, z);
  477.       glVertex3f(-y, -x, z);
  478.       glVertex3f(-y, -x, -z);
  479.       glVertex3f(-y, x, -z);
  480.       glEnd();
  481.       if (solid)
  482.         glBegin(GL_TRIANGLES);
  483.       glNormal3f(0.0, 0.0, 1.0);
  484.       glVertex3f(0.0, 0.0, z);
  485.       glVertex3f(-y, x, z);
  486.       glVertex3f(-y, -x, z);
  487.       glNormal3f(0.0, 0.0, -1.0);
  488.       glVertex3f(0.0, 0.0, -z);
  489.       glVertex3f(-y, -x, -z);
  490.       glVertex3f(-y, x, -z);
  491.       glEnd();
  492.       j = 1;
  493.     }
  494.   }
  495. }
  496.  
  497. void
  498. Octagon(float side, float height, char solid)
  499. {
  500.   char j;
  501.   float x = sin(0.785398163) * side, y = side / 2.0, z = height / 2.0, c;
  502.  
  503.   c = x + y;
  504.   for (j = 0; j < 8; j++) {
  505.     glTranslatef(-c, 0.0, 0.0);
  506.     if (!solid)
  507.       glBegin(GL_LINE_LOOP);
  508.     else
  509.       glBegin(GL_QUADS);
  510.     glNormal3f(-1.0, 0.0, 0.0);
  511.     glVertex3f(0.0, -y, z);
  512.     glVertex3f(0.0, y, z);
  513.     glVertex3f(0.0, y, -z);
  514.     glVertex3f(0.0, -y, -z);
  515.     glEnd();
  516.     glTranslatef(c, 0.0, 0.0);
  517.     if (solid) {
  518.       glBegin(GL_TRIANGLES);
  519.       glNormal3f(0.0, 0.0, 1.0);
  520.       glVertex3f(0.0, 0.0, z);
  521.       glVertex3f(-c, -y, z);
  522.       glVertex3f(-c, y, z);
  523.       glNormal3f(0.0, 0.0, -1.0);
  524.       glVertex3f(0.0, 0.0, -z);
  525.       glVertex3f(-c, y, -z);
  526.       glVertex3f(-c, -y, -z);
  527.       glEnd();
  528.     }
  529.     glRotatef(45.0, 0.0, 0.0, 1.0);
  530.   }
  531. }
  532.  
  533. /* end of geometric shape functions */
  534. #ifdef NORM
  535. void
  536. Normalize(float v[3])
  537. {
  538.   GLfloat d = sqrt(v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
  539.  
  540.   if (d == 0.0) {
  541.     printf("zero length vector");
  542.     return;
  543.   }
  544.   v[1] /= d;
  545.   v[2] /= d;
  546.   v[3] /= d;
  547. }
  548.  
  549. void
  550. NormXprod(float v1[3], float v2[3], float v[3], float out[3])
  551. {
  552.   GLint i, j;
  553.   GLfloat length;
  554.  
  555.   out[0] = v1[1] * v2[2] - v1[2] * v2[1];
  556.   out[1] = v1[2] * v2[0] - v1[0] * v2[2];
  557.   out[2] = v1[0] * v2[1] - v1[1] * v2[0];
  558.   Normalize(out);
  559. }
  560.  
  561. #endif
  562.  
  563. void
  564. SetMaterial(GLfloat spec[], GLfloat amb[], GLfloat diff[], GLfloat shin[])
  565. {
  566.  
  567.   glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
  568.   glMaterialfv(GL_FRONT, GL_SHININESS, shin);
  569.   glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
  570.   glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
  571. }
  572.  
  573. void
  574. MechTorso(char solid)
  575. {
  576.   glNewList(SOLID_MECH_TORSO, GL_COMPILE);
  577. #ifdef LIGHT
  578.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  579. #endif
  580.   glColor3f(1.0, 1.0, 0.0);
  581.   Box(1.0, 1.0, 3.0, solid);
  582.   glTranslatef(0.75, 0.0, 0.0);
  583. #ifdef LIGHT
  584.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  585. #endif
  586.   glColor3f(0.5, 0.5, 0.5);
  587.   Box(0.5, 0.6, 2.0, solid);
  588.   glTranslatef(-1.5, 0.0, 0.0);
  589.   Box(0.5, 0.6, 2.0, solid);
  590.   glTranslatef(0.75, 0.0, 0.0);
  591.   glEndList();
  592. }
  593.  
  594. void
  595. MechHip(char solid)
  596. {
  597.   int i;
  598.   GLUquadricObj *hip[2];
  599.  
  600.   glNewList(SOLID_MECH_HIP, GL_COMPILE);
  601. #ifdef LIGHT
  602.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  603. #endif
  604.   glColor3f(1.0, 1.0, 0.0);
  605.   Octagon(0.7, 0.5, solid);
  606. #ifdef SPHERE
  607.   for (i = 0; i < 2; i++) {
  608.     if (i)
  609.       glScalef(-1.0, 1.0, 1.0);
  610.     glTranslatef(1.0, 0.0, 0.0);
  611.     hip[i] = gluNewQuadric();
  612. #ifdef LIGHT
  613.     SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  614. #endif
  615.     glColor3f(0.5, 0.5, 0.5);
  616.     if (!solid)
  617.       gluQuadricDrawStyle(hip[i], GLU_LINE);
  618.     gluSphere(hip[0], 0.2, 16, 16);
  619.     glTranslatef(-1.0, 0.0, 0.0);
  620.   }
  621.   glScalef(-1.0, 1.0, 1.0);
  622. #endif
  623.   glEndList();
  624. }
  625.  
  626. void
  627. Shoulder(char solid)
  628. {
  629.   GLUquadricObj *deltoid = gluNewQuadric();
  630.  
  631.   glNewList(SOLID_MECH_SHOULDER, GL_COMPILE);
  632. #ifdef LIGHT
  633.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  634. #endif
  635.   glColor3f(1.0, 1.0, 0.0);
  636.   Box(1.0, 0.5, 0.5, solid);
  637.   glTranslatef(0.9, 0.0, 0.0);
  638. #ifdef LIGHT
  639.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  640. #endif
  641.   glColor3f(0.5, 0.5, 0.5);
  642. #ifdef SPHERE
  643.   if (!solid)
  644.     gluQuadricDrawStyle(deltoid, GLU_LINE);
  645.   gluSphere(deltoid, 0.6, 16, 16);
  646. #endif
  647.   glTranslatef(-0.9, 0.0, 0.0);
  648.   glEndList();
  649. }
  650.  
  651. void
  652. UpperArm(char solid)
  653. {
  654.   GLUquadricObj *upper = gluNewQuadric();
  655.   GLUquadricObj *joint[2];
  656.   GLUquadricObj *joint1[2];
  657.   int i;
  658.  
  659.   glNewList(SOLID_MECH_UPPER_ARM, GL_COMPILE);
  660. #ifdef LIGHT
  661.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  662. #endif
  663.   glColor3f(1.0, 1.0, 0.0);
  664.   Box(1.0, 2.0, 1.0, solid);
  665.   glTranslatef(0.0, -0.95, 0.0);
  666.   glRotatef(90.0, 1.0, 0.0, 0.0);
  667. #ifdef LIGHT
  668.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  669. #endif
  670.   glColor3f(0.5, 0.5, 0.5);
  671.   if (!solid)
  672.     gluQuadricDrawStyle(upper, GLU_LINE);
  673.   gluCylinder(upper, 0.4, 0.4, 1.5, 16, 10);
  674. #ifdef LIGHT
  675.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  676. #endif
  677.   glColor3f(1.0, 1.0, 0.0);
  678.   glRotatef(-90.0, 1.0, 0.0, 0.0);
  679.   glTranslatef(-0.4, -1.85, 0.0);
  680.   glRotatef(90.0, 0.0, 1.0, 0.0);
  681.   for (i = 0; i < 2; i++) {
  682.     joint[i] = gluNewQuadric();
  683.     if (!solid)
  684.       gluQuadricDrawStyle(joint[i], GLU_LINE);
  685.     if (i)
  686.       gluCylinder(joint[i], 0.5, 0.5, 0.8, 16, 10);
  687.     else
  688.       gluCylinder(joint[i], 0.2, 0.2, 0.8, 16, 10);
  689.   }
  690.   for (i = 0; i < 2; i++) {
  691.     if (i)
  692.       glScalef(-1.0, 1.0, 1.0);
  693.     joint1[i] = gluNewQuadric();
  694.     if (!solid)
  695.       gluQuadricDrawStyle(joint1[i], GLU_LINE);
  696.     if (i)
  697.       glTranslatef(0.0, 0.0, 0.8);
  698.     gluDisk(joint1[i], 0.2, 0.5, 16, 10);
  699.     if (i)
  700.       glTranslatef(0.0, 0.0, -0.8);
  701.   }
  702.   glScalef(-1.0, 1.0, 1.0);
  703.   glRotatef(-90.0, 0.0, 1.0, 0.0);
  704.   glTranslatef(0.4, 2.9, 0.0);
  705.   glEndList();
  706. }
  707.  
  708. void
  709. VulcanGun(char solid)
  710. {
  711.   int i;
  712.   GLUquadricObj *Barrel[5];
  713.   GLUquadricObj *BarrelFace[5];
  714.   GLUquadricObj *Barrel2[5];
  715.   GLUquadricObj *Barrel3[5];
  716.   GLUquadricObj *BarrelFace2[5];
  717.   GLUquadricObj *Mount = gluNewQuadric();
  718.   GLUquadricObj *Mount_face = gluNewQuadric();
  719.  
  720.   glNewList(SOLID_MECH_VULCAN, GL_COMPILE);
  721.  
  722. #ifdef LIGHT
  723.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  724. #endif
  725.   glColor3f(0.5, 0.5, 0.5);
  726.  
  727.   if (!solid) {
  728.     gluQuadricDrawStyle(Mount, GLU_LINE);
  729.     gluQuadricDrawStyle(Mount_face, GLU_LINE);
  730.   }
  731.   gluCylinder(Mount, 0.5, 0.5, 0.5, 16, 10);
  732.   glTranslatef(0.0, 0.0, 0.5);
  733.   gluDisk(Mount_face, 0.0, 0.5, 16, 10);
  734.  
  735.   for (i = 0; i < 5; i++) {
  736.     Barrel[i] = gluNewQuadric();
  737.     BarrelFace[i] = gluNewQuadric();
  738.     BarrelFace2[i] = gluNewQuadric();
  739.     Barrel2[i] = gluNewQuadric();
  740.     Barrel3[i] = gluNewQuadric();
  741.     glRotatef(72.0, 0.0, 0.0, 1.0);
  742.     glTranslatef(0.0, 0.3, 0.0);
  743.     if (!solid) {
  744.       gluQuadricDrawStyle(Barrel[i], GLU_LINE);
  745.       gluQuadricDrawStyle(BarrelFace[i], GLU_LINE);
  746.       gluQuadricDrawStyle(BarrelFace2[i], GLU_LINE);
  747.       gluQuadricDrawStyle(Barrel2[i], GLU_LINE);
  748.       gluQuadricDrawStyle(Barrel3[i], GLU_LINE);
  749.     }
  750.     gluCylinder(Barrel[i], 0.15, 0.15, 2.0, 16, 10);
  751.     gluCylinder(Barrel3[i], 0.06, 0.06, 2.0, 16, 10);
  752.     glTranslatef(0.0, 0.0, 2.0);
  753.     gluDisk(BarrelFace[i], 0.1, 0.15, 16, 10);
  754.     gluCylinder(Barrel2[i], 0.1, 0.1, 0.1, 16, 5);
  755.     glTranslatef(0.0, 0.0, 0.1);
  756.     gluDisk(BarrelFace2[i], 0.06, 0.1, 16, 5);
  757.     glTranslatef(0.0, -0.3, -2.1);
  758.   }
  759.   glEndList();
  760. }
  761.  
  762. void
  763. ForeArm(char solid)
  764. {
  765.   char i;
  766.  
  767.   glNewList(SOLID_MECH_FOREARM, GL_COMPILE);
  768. #ifdef LIGHT
  769.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  770. #endif
  771.   glColor3f(1.0, 1.0, 0.0);
  772.   for (i = 0; i < 5; i++) {
  773.     glTranslatef(0.0, -0.1, -0.15);
  774.     Box(0.6, 0.8, 0.2, solid);
  775.     glTranslatef(0.0, 0.1, -0.15);
  776.     Box(0.4, 0.6, 0.1, solid);
  777.   }
  778.   glTranslatef(0.0, 0.0, 2.45);
  779.   Box(1.0, 1.0, 2.0, solid);
  780.   glTranslatef(0.0, 0.0, -1.0);
  781.   glEndList();
  782. }
  783.  
  784. void
  785. UpperLeg(char solid)
  786. {
  787.   int i;
  788.   GLUquadricObj *Hamstring = gluNewQuadric();
  789.   GLUquadricObj *Knee = gluNewQuadric();
  790.   GLUquadricObj *joint[2];
  791.  
  792.   glNewList(SOLID_MECH_UPPER_LEG, GL_COMPILE);
  793. #ifdef LIGHT
  794.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  795. #endif
  796.   glColor3f(1.0, 1.0, 0.0);
  797.   if (!solid) {
  798.     gluQuadricDrawStyle(Hamstring, GLU_LINE);
  799.     gluQuadricDrawStyle(Knee, GLU_LINE);
  800.   }
  801.   glTranslatef(0.0, -1.0, 0.0);
  802.   Box(0.4, 1.0, 0.7, solid);
  803.   glTranslatef(0.0, -0.65, 0.0);
  804.   for (i = 0; i < 5; i++) {
  805.     Box(1.2, 0.3, 1.2, solid);
  806.     glTranslatef(0.0, -0.2, 0.0);
  807.     Box(1.0, 0.1, 1.0, solid);
  808.     glTranslatef(0.0, -0.2, 0.0);
  809.   }
  810.   glTranslatef(0.0, -0.15, -0.4);
  811.   Box(2.0, 0.5, 2.0, solid);
  812.   glTranslatef(0.0, -0.3, -0.2);
  813.   glRotatef(90.0, 1.0, 0.0, 0.0);
  814. #ifdef LIGHT
  815.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  816. #endif
  817.   glColor3f(0.5, 0.5, 0.5);
  818.   gluCylinder(Hamstring, 0.6, 0.6, 3.0, 16, 10);
  819. #ifdef LIGHT
  820.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  821. #endif
  822.   glColor3f(1.0, 1.0, 0.0);
  823.   glRotatef(-90.0, 1.0, 0.0, 0.0);
  824.   glTranslatef(0.0, -1.5, 1.0);
  825.   Box(1.5, 3.0, 0.5, solid);
  826.   glTranslatef(0.0, -1.75, -0.8);
  827.   Box(2.0, 0.5, 2.0, solid);
  828.   glTranslatef(0.0, -0.9, -0.85);
  829. #ifdef LIGHT
  830.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  831. #endif
  832.   glColor3f(0.5, 0.5, 0.5);
  833.   gluCylinder(Knee, 0.8, 0.8, 1.8, 16, 10);
  834.   for (i = 0; i < 2; i++) {
  835.     if (i)
  836.       glScalef(-1.0, 1.0, 1.0);
  837.     joint[i] = gluNewQuadric();
  838.     if (!solid)
  839.       gluQuadricDrawStyle(joint[i], GLU_LINE);
  840.     if (i)
  841.       glTranslatef(0.0, 0.0, 1.8);
  842.     gluDisk(joint[i], 0.0, 0.8, 16, 10);
  843.     if (i)
  844.       glTranslatef(0.0, 0.0, -1.8);
  845.   }
  846.   glScalef(-1.0, 1.0, 1.0);
  847.   glEndList();
  848. }
  849.  
  850. void
  851. Foot(char solid)
  852. {
  853.  
  854.   glNewList(SOLID_MECH_FOOT, GL_COMPILE);
  855. #ifdef LIGHT
  856.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  857. #endif
  858.   glColor3f(0.5, 0.5, 0.5);
  859.   glRotatef(90.0, 1.0, 0.0, 0.0);
  860.   Octagon(1.5, 0.6, solid);
  861.   glRotatef(-90.0, 1.0, 0.0, 0.0);
  862.   glEndList();
  863. }
  864.  
  865. void
  866. LowerLeg(char solid)
  867. {
  868.   float k, l;
  869.   GLUquadricObj *ankle = gluNewQuadric();
  870.   GLUquadricObj *ankle_face[2];
  871.  
  872. #ifdef LIGHT
  873.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  874. #endif
  875.   glColor3f(1.0, 1.0, 0.0);
  876.   for (k = 0.0; k < 2.0; k++) {
  877.     for (l = 0.0; l < 2.0; l++) {
  878.       glPushMatrix();
  879.       glTranslatef(k, 0.0, l);
  880. #ifdef LIGHT
  881.       SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  882. #endif
  883.       glColor3f(1.0, 1.0, 0.0);
  884.       Box(1.0, 0.5, 1.0, solid);
  885.       glTranslatef(0.0, -0.45, 0.0);
  886. #ifdef LIGHT
  887.       SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  888. #endif
  889.       glColor3f(0.5, 0.5, 0.5);
  890. #ifdef SPHERE
  891.       if (!solid)
  892.         glutWireSphere(0.2, 16, 10);
  893.       else
  894.         glutSolidSphere(0.2, 16, 10);
  895.       /* joints[i] = gluNewQuadric();
  896.          if(!solid)gluQuadricDrawStyle(joints[i], GLU_LINE);
  897.          gluSphere(joints[i],0.2, 16, 16); i++; */
  898. #endif
  899.       if (leg)
  900.         glRotatef((GLfloat) heel1, 1.0, 0.0, 0.0);
  901.       else
  902.         glRotatef((GLfloat) heel2, 1.0, 0.0, 0.0);
  903.       /* glTranslatef(0.0, -0.2, 0.0); */
  904.       glTranslatef(0.0, -1.7, 0.0);
  905. #ifdef LIGHT
  906.       SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  907. #endif
  908.       glColor3f(1.0, 1.0, 0.0);
  909.       Box(0.25, 3.0, 0.25, solid);
  910.       glTranslatef(0.0, -1.7, 0.0);
  911. #ifdef LIGHT
  912.       SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  913. #endif
  914.       glColor3f(0.5, 0.5, 0.5);
  915. #ifdef SPHERE
  916.       if (!solid)
  917.         glutWireSphere(0.2, 16, 10);
  918.       else
  919.         glutSolidSphere(0.2, 16, 10);
  920.       /* joints[i] = gluNewQuadric();
  921.          if(!solid)gluQuadricDrawStyle(joints[i], GLU_LINE);
  922.          gluSphere(joints[i], 0.2, 16, 16);      i++; */
  923. #endif
  924.       if (leg)
  925.         glRotatef((GLfloat) - heel1, 1.0, 0.0, 0.0);
  926.       else
  927.         glRotatef((GLfloat) - heel2, 1.0, 0.0, 0.0);
  928.       glTranslatef(0.0, -0.45, 0.0);
  929. #ifdef LIGHT
  930.       SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  931. #endif
  932.       glColor3f(1.0, 1.0, 0.0);
  933.       Box(1.0, 0.5, 1.0, solid);
  934.       if (!k && !l) {
  935.         int j;
  936.  
  937.         glTranslatef(-0.4, -0.8, 0.5);
  938.         if (leg)
  939.           glRotatef((GLfloat) ankle1, 1.0, 0.0, 0.0);
  940.         else
  941.           glRotatef((GLfloat) ankle2, 1.0, 0.0, 0.0);
  942.         glRotatef(90.0, 0.0, 1.0, 0.0);
  943.         if (!solid)
  944.           gluQuadricDrawStyle(ankle, GLU_LINE);
  945.         gluCylinder(ankle, 0.8, 0.8, 1.8, 16, 10);
  946.         for (j = 0; j < 2; j++) {
  947.           ankle_face[j] = gluNewQuadric();
  948.           if (!solid)
  949.             gluQuadricDrawStyle(ankle_face[j], GLU_LINE);
  950.           if (j) {
  951.             glScalef(-1.0, 1.0, 1.0);
  952.             glTranslatef(0.0, 0.0, 1.8);
  953.           }
  954.           gluDisk(ankle_face[j], 0.0, 0.8, 16, 10);
  955.           if (j)
  956.             glTranslatef(0.0, 0.0, -1.8);
  957.         }
  958.         glScalef(-1.0, 1.0, 1.0);
  959.         glRotatef(-90.0, 0.0, 1.0, 0.0);
  960.         glTranslatef(0.95, -0.8, 0.0);
  961.         glCallList(SOLID_MECH_FOOT);
  962.       }
  963.       glPopMatrix();
  964.     }
  965.   }
  966. }
  967.  
  968. void
  969. RocketPod(char solid)
  970. {
  971.  
  972.   int i, j, k = 0;
  973.   GLUquadricObj *rocket[6];
  974.   GLUquadricObj *rocket1[6];
  975.  
  976.   glNewList(SOLID_MECH_ROCKET, GL_COMPILE);
  977. #ifdef LIGHT
  978.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  979. #endif
  980.   glColor3f(0.5, 0.5, 0.5);
  981.   glScalef(0.4, 0.4, 0.4);
  982.   glRotatef(45.0, 0.0, 0.0, 1.0);
  983.   glTranslatef(1.0, 0.0, 0.0);
  984.   Box(2.0, 0.5, 3.0, solid);
  985.   glTranslatef(1.0, 0.0, 0.0);
  986.   glRotatef(45.0, 0.0, 0.0, 1.0);
  987.   glTranslatef(0.5, 0.0, 0.0);
  988.   Box(1.2, 0.5, 3.0, solid);
  989.   glTranslatef(2.1, 0.0, 0.0);
  990.   glRotatef(-90.0, 0.0, 0.0, 1.0);
  991. #ifdef LIGHT
  992.   SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
  993. #endif
  994.   glColor3f(1.0, 1.0, 0.0);
  995.   Box(2.0, 3.0, 4.0, solid);
  996.   glTranslatef(-0.5, -1.0, 1.3);
  997.   for (i = 0; i < 2; i++) {
  998.     for (j = 0; j < 3; j++) {
  999.       rocket[k] = gluNewQuadric();
  1000.       rocket1[k] = gluNewQuadric();
  1001.       if (!solid) {
  1002.         gluQuadricDrawStyle(rocket[k], GLU_LINE);
  1003.         gluQuadricDrawStyle(rocket1[k], GLU_LINE);
  1004.       }
  1005.       glTranslatef(i, j, 0.6);
  1006. #ifdef LIGHT
  1007.       SetMaterial(mat_specular3, mat_ambient3, mat_diffuse3, mat_shininess3);
  1008. #endif
  1009.       glColor3f(1.0, 1.0, 1.0);
  1010.       gluCylinder(rocket[k], 0.4, 0.4, 0.3, 16, 10);
  1011.       glTranslatef(0.0, 0.0, 0.3);
  1012. #ifdef LIGHT
  1013.       SetMaterial(mat_specular4, mat_ambient4, mat_diffuse4, mat_shininess4);
  1014. #endif
  1015.       glColor3f(0.0, 1.0, 0.0);
  1016.       gluCylinder(rocket1[k], 0.4, 0.0, 0.5, 16, 10);
  1017.       k++;
  1018.       glTranslatef(-i, -j, -0.9);
  1019.     }
  1020.   }
  1021.   glEndList();
  1022. }
  1023.  
  1024. void
  1025. Enviro(char solid)
  1026. {
  1027.  
  1028.   int i, j;
  1029.  
  1030.   glNewList(SOLID_ENVIRO, GL_COMPILE);
  1031.   SetMaterial(mat_specular4, mat_ambient4, mat_diffuse4, mat_shininess4);
  1032.   glColor3f(0.0, 1.0, 0.0);
  1033.   Box(20.0, 0.5, 30.0, solid);
  1034.   SetMaterial(mat_specular4, mat_ambient3, mat_diffuse2, mat_shininess);
  1035.   glColor3f(0.6, 0.6, 0.6);
  1036.   glTranslatef(0.0, 0.0, -10.0);
  1037.   for (j = 0; j < 6; j++) {
  1038.     for (i = 0; i < 2; i++) {
  1039.       if (i)
  1040.         glScalef(-1.0, 1.0, 1.0);
  1041.       glTranslatef(10.0, 4.0, 0.0);
  1042.       Box(4.0, 8.0, 2.0, solid);
  1043.       glTranslatef(0.0, -1.0, -3.0);
  1044.       Box(4.0, 6.0, 2.0, solid);
  1045.       glTranslatef(-10.0, -3.0, 3.0);
  1046.     }
  1047.     glScalef(-1.0, 1.0, 1.0);
  1048.     glTranslatef(0.0, 0.0, 5.0);
  1049.   }
  1050.   glEndList();
  1051. }
  1052.  
  1053. void
  1054. Toggle(void)
  1055. {
  1056.   if (solid_part)
  1057.     solid_part = 0;
  1058.   else
  1059.     solid_part = 1;
  1060. }
  1061.  
  1062. void
  1063. disable(void)
  1064. {
  1065.   glDisable(GL_LIGHTING);
  1066.   glDisable(GL_DEPTH_TEST);
  1067.   glDisable(GL_NORMALIZE);
  1068.   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  1069. }
  1070.  
  1071. void
  1072. lighting(void)
  1073. {
  1074.  
  1075.   GLfloat position[] =
  1076.   {0.0, 0.0, 2.0, 1.0};
  1077.  
  1078. #ifdef MOVE_LIGHT
  1079.   glRotatef((GLfloat) lightturn1, 1.0, 0.0, 0.0);
  1080.   glRotatef((GLfloat) lightturn, 0.0, 1.0, 0.0);
  1081.   glRotatef(0.0, 1.0, 0.0, 0.0);
  1082. #endif
  1083.   glEnable(GL_LIGHTING);
  1084.   glEnable(GL_LIGHT0);
  1085.   glEnable(GL_NORMALIZE);
  1086.   glEnable(GL_FLAT);
  1087.   glDepthFunc(GL_LESS);
  1088.   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  1089.  
  1090.   glLightfv(GL_LIGHT0, GL_POSITION, position);
  1091.   glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 80.0);
  1092.  
  1093.   glTranslatef(0.0, 0.0, 2.0);
  1094.   glDisable(GL_LIGHTING);
  1095.   Box(0.1, 0.1, 0.1, 0);
  1096.   glEnable(GL_LIGHTING);
  1097. }
  1098.  
  1099. void
  1100. DrawMech(void)
  1101. {
  1102.   int i, j;
  1103.  
  1104.   glScalef(0.5, 0.5, 0.5);
  1105.   glPushMatrix();
  1106.   glTranslatef(0.0, -0.75, 0.0);
  1107.   glRotatef((GLfloat) tilt, 1.0, 0.0, 0.0);
  1108.  
  1109.   glRotatef(90.0, 1.0, 0.0, 0.0);
  1110. #ifdef HIP
  1111.   glCallList(SOLID_MECH_HIP);
  1112. #endif
  1113.   glRotatef(-90.0, 1.0, 0.0, 0.0);
  1114.  
  1115.   glTranslatef(0.0, 0.75, 0.0);
  1116.   glPushMatrix();
  1117.   glRotatef((GLfloat) pivot, 0.0, 1.0, 0.0);
  1118.   glPushMatrix();
  1119. #ifdef TORSO
  1120.   glCallList(SOLID_MECH_TORSO);
  1121. #endif
  1122.   glPopMatrix();
  1123.   glPushMatrix();
  1124.   glTranslatef(0.5, 0.5, 0.0);
  1125. #ifdef ROCKET_POD
  1126.   glCallList(SOLID_MECH_ROCKET);
  1127. #endif
  1128.   glPopMatrix();
  1129.   for (i = 0; i < 2; i++) {
  1130.     glPushMatrix();
  1131.     if (i)
  1132.       glScalef(-1.0, 1.0, 1.0);
  1133.     glTranslatef(1.5, 0.0, 0.0);
  1134. #ifdef SHOULDER
  1135.     glCallList(SOLID_MECH_SHOULDER);
  1136. #endif
  1137.     glTranslatef(0.9, 0.0, 0.0);
  1138.     if (i) {
  1139.       glRotatef((GLfloat) lat1, 0.0, 0.0, 1.0);
  1140.       glRotatef((GLfloat) shoulder1, 1.0, 0.0, 0.0);
  1141.       glRotatef((GLfloat) shoulder3, 0.0, 1.0, 0.0);
  1142.     } else {
  1143.       glRotatef((GLfloat) lat2, 0.0, 0.0, 1.0);
  1144.       glRotatef((GLfloat) shoulder2, 1.0, 0.0, 0.0);
  1145.       glRotatef((GLfloat) shoulder4, 0.0, 1.0, 0.0);
  1146.     }
  1147.     glTranslatef(0.0, -1.4, 0.0);
  1148. #ifdef UPPER_ARM
  1149.     glCallList(SOLID_MECH_UPPER_ARM);
  1150. #endif
  1151.     glTranslatef(0.0, -2.9, 0.0);
  1152.     if (i)
  1153.       glRotatef((GLfloat) elbow1, 1.0, 0.0, 0.0);
  1154.     else
  1155.       glRotatef((GLfloat) elbow2, 1.0, 0.0, 0.0);
  1156.     glTranslatef(0.0, -0.9, -0.2);
  1157. #ifdef LOWER_ARM
  1158.     glCallList(SOLID_MECH_FOREARM);
  1159.     glPushMatrix();
  1160.     glTranslatef(0.0, 0.0, 2.0);
  1161.     glRotatef((GLfloat) fire, 0.0, 0.0, 1.0);
  1162.     glCallList(SOLID_MECH_VULCAN);
  1163.     glPopMatrix();
  1164. #endif
  1165.     glPopMatrix();
  1166.   }
  1167.   glPopMatrix();
  1168.  
  1169.   glPopMatrix();
  1170.  
  1171.   for (j = 0; j < 2; j++) {
  1172.     glPushMatrix();
  1173.     if (j) {
  1174.       glScalef(-0.5, 0.5, 0.5);
  1175.       leg = 1;
  1176.     } else {
  1177.       glScalef(0.5, 0.5, 0.5);
  1178.       leg = 0;
  1179.     }
  1180.     glTranslatef(2.0, -1.5, 0.0);
  1181.     if (j) {
  1182.       glRotatef((GLfloat) hip11, 1.0, 0.0, 0.0);
  1183.       glRotatef((GLfloat) hip12, 0.0, 0.0, 1.0);
  1184.     } else {
  1185.       glRotatef((GLfloat) hip21, 1.0, 0.0, 0.0);
  1186.       glRotatef((GLfloat) hip22, 0.0, 0.0, 1.0);
  1187.     }
  1188.     glTranslatef(0.0, 0.3, 0.0);
  1189. #ifdef UPPER_LEG
  1190.     glPushMatrix();
  1191.     glCallList(SOLID_MECH_UPPER_LEG);
  1192.     glPopMatrix();
  1193. #endif
  1194.     glTranslatef(0.0, -8.3, -0.4);
  1195.     if (j)
  1196.       glRotatef((GLfloat) - hip12, 0.0, 0.0, 1.0);
  1197.     else
  1198.       glRotatef((GLfloat) - hip22, 0.0, 0.0, 1.0);
  1199.     glTranslatef(-0.5, -0.85, -0.5);
  1200. #ifdef LOWER_LEG
  1201.     LowerLeg(1);
  1202. #endif
  1203.     glPopMatrix();
  1204.   }
  1205. }
  1206.  
  1207. void
  1208. display(void)
  1209. {
  1210.   glClearColor(0.0, 0.0, 0.0, 0.0);
  1211.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1212.   glEnable(GL_DEPTH_TEST);
  1213.  
  1214.   glPushMatrix();
  1215.   glRotatef((GLfloat) turn, 0.0, 1.0, 0.0);
  1216.   glRotatef((GLfloat) turn1, 1.0, 0.0, 0.0);
  1217. #ifdef LIGHT
  1218.   if (solid_part) {
  1219.     glPushMatrix();
  1220.     lighting();
  1221.     glPopMatrix();
  1222.   } else
  1223.     disable();
  1224. #endif
  1225. #ifdef DRAW_MECH
  1226.   glPushMatrix();
  1227.   glTranslatef(0.0, elevation, 0.0);
  1228.   DrawMech();
  1229.   glPopMatrix();
  1230. #endif
  1231. #ifdef DRAW_ENVIRO
  1232.   glPushMatrix();
  1233.   if (distance >= 20.136)
  1234.     distance = 0.0;
  1235.   glTranslatef(0.0, -5.0, -distance);
  1236.   glCallList(SOLID_ENVIRO);
  1237.   glTranslatef(0.0, 0.0, 10.0);
  1238.   glCallList(SOLID_ENVIRO);
  1239.   glPopMatrix();
  1240. #endif
  1241.   glPopMatrix();
  1242.   glFlush();
  1243.   glutSwapBuffers();
  1244. }
  1245.  
  1246. void
  1247. myinit(void)
  1248. {
  1249.   char i = 1;
  1250.  
  1251. #ifdef LIGHT
  1252.   SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
  1253. #endif
  1254.   glEnable(GL_DEPTH_TEST);
  1255.   MechTorso(i);
  1256.   MechHip(i);
  1257.   Shoulder(i);
  1258.   RocketPod(i);
  1259.   UpperArm(i);
  1260.   ForeArm(i);
  1261.   UpperLeg(i);
  1262.   Foot(i);
  1263.   VulcanGun(i);
  1264.   Enviro(i);
  1265. }
  1266.  
  1267. void
  1268. myReshape(int w, int h)
  1269. {
  1270.   glViewport(0, 0, w, h);
  1271.   glMatrixMode(GL_PROJECTION);
  1272.   glLoadIdentity();
  1273.   gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 1.0, 20.0);
  1274.   glMatrixMode(GL_MODELVIEW);
  1275.   glLoadIdentity();
  1276.   glTranslatef(0.0, 1.2, -5.5);  /* viewing transform  */
  1277. }
  1278.  
  1279. #ifdef ANIMATION
  1280. void
  1281. animation_walk(void)
  1282. {
  1283.   float angle;
  1284.   static int step;
  1285.  
  1286.   if (step == 0 || step == 2) {
  1287.     /* for(frame=3.0; frame<=21.0; frame=frame+3.0){ */
  1288.     if (frame >= 0.0 && frame <= 21.0) {
  1289.       if (frame == 0.0)
  1290.         frame = 3.0;
  1291.       angle = (180 / PI) * (acos(((cos((PI / 180) * frame) * 2.043) + 1.1625) / 3.2059));
  1292.       if (frame > 0) {
  1293.         elevation = -(3.2055 - (cos((PI / 180) * angle) * 3.2055));
  1294.       } else
  1295.         elevation = 0.0;
  1296.       if (step == 0) {
  1297.         hip11 = -(frame * 1.7);
  1298.         if (1.7 * frame > 15)
  1299.           heel1 = frame * 1.7;
  1300.         heel2 = 0;
  1301.         ankle1 = frame * 1.7;
  1302.         if (frame > 0)
  1303.           hip21 = angle;
  1304.         else
  1305.           hip21 = 0;
  1306.         ankle2 = -hip21;
  1307.         shoulder1 = frame * 1.5;
  1308.         shoulder2 = -frame * 1.5;
  1309.         elbow1 = frame;
  1310.         elbow2 = -frame;
  1311.       } else {
  1312.         hip21 = -(frame * 1.7);
  1313.         if (1.7 * frame > 15)
  1314.           heel2 = frame * 1.7;
  1315.         heel1 = 0;
  1316.         ankle2 = frame * 1.7;
  1317.         if (frame > 0)
  1318.           hip11 = angle;
  1319.         else
  1320.           hip11 = 0;
  1321.         ankle1 = -hip11;
  1322.         shoulder1 = -frame * 1.5;
  1323.         shoulder2 = frame * 1.5;
  1324.         elbow1 = -frame;
  1325.         elbow2 = frame;
  1326.       }
  1327.       if (frame == 21)
  1328.         step++;
  1329.       if (frame < 21)
  1330.         frame = frame + 3.0;
  1331.     }
  1332.   }
  1333.   if (step == 1 || step == 3) {
  1334.     /* for(x=21.0; x>=0.0; x=x-3.0){ */
  1335.     if (frame <= 21.0 && frame >= 0.0) {
  1336.       angle = (180 / PI) * (acos(((cos((PI / 180) * frame) * 2.043) + 1.1625) / 3.2029));
  1337.       if (frame > 0)
  1338.         elevation = -(3.2055 - (cos((PI / 180) * angle) * 3.2055));
  1339.       else
  1340.         elevation = 0.0;
  1341.       if (step == 1) {
  1342.         elbow2 = hip11 = -frame;
  1343.         elbow1 = heel1 = frame;
  1344.         heel2 = 15;
  1345.         ankle1 = frame;
  1346.         if (frame > 0)
  1347.           hip21 = angle;
  1348.         else
  1349.           hip21 = 0;
  1350.         ankle2 = -hip21;
  1351.         shoulder1 = 1.5 * frame;
  1352.         shoulder2 = -frame * 1.5;
  1353.       } else {
  1354.         elbow1 = hip21 = -frame;
  1355.         elbow2 = heel2 = frame;
  1356.         heel1 = 15;
  1357.         ankle2 = frame;
  1358.         if (frame > 0)
  1359.           hip11 = angle;
  1360.         else
  1361.           hip11 = 0;
  1362.         ankle1 = -hip11;
  1363.         shoulder1 = -frame * 1.5;
  1364.         shoulder2 = frame * 1.5;
  1365.       }
  1366.       if (frame == 0.0)
  1367.         step++;
  1368.       if (frame > 0)
  1369.         frame = frame - 3.0;
  1370.     }
  1371.   }
  1372.   if (step == 4)
  1373.     step = 0;
  1374.   distance += 0.1678;
  1375.   glutPostRedisplay();
  1376. }
  1377.  
  1378. void
  1379. animation(void)
  1380. {
  1381.   animation_walk();
  1382. }
  1383.  
  1384. #endif
  1385.  
  1386. #ifdef GLUT
  1387. #ifdef GLUT_KEY
  1388. void
  1389. keyboard(unsigned char key, int x, int y)
  1390. {
  1391.  
  1392.   int i = 0;
  1393.  
  1394.   switch (key) {
  1395.     /* start arm control functions */
  1396.   case 'q':{
  1397.       shoulder2Subtract();
  1398.       i++;
  1399.     }
  1400.     break;
  1401.   case 'a':{
  1402.       shoulder2Add();
  1403.       i++;
  1404.     }
  1405.     break;
  1406.   case 'w':{
  1407.       shoulder1Subtract();
  1408.       i++;
  1409.     }
  1410.     break;
  1411.   case 's':{
  1412.       shoulder1Add();
  1413.       i++;
  1414.     }
  1415.     break;
  1416.   case '2':{
  1417.       shoulder3Add();
  1418.       i++;
  1419.     }
  1420.     break;
  1421.   case '1':{
  1422.       shoulder4Add();
  1423.       i++;
  1424.     }
  1425.     break;
  1426.   case '4':{
  1427.       shoulder3Subtract();
  1428.       i++;
  1429.     }
  1430.     break;
  1431.   case '3':{
  1432.       shoulder4Subtract();
  1433.       i++;
  1434.     }
  1435.     break;
  1436.  
  1437.   case 'z':{
  1438.       lat2Raise();
  1439.       i++;
  1440.     }
  1441.     break;
  1442.   case 'Z':{
  1443.       lat2Lower();
  1444.       i++;
  1445.     }
  1446.     break;
  1447.   case 'x':{
  1448.       lat1Raise();
  1449.       i++;
  1450.     }
  1451.     break;
  1452.   case 'X':{
  1453.       lat1Lower();
  1454.       i++;
  1455.     }
  1456.     break;
  1457.  
  1458.   case 'A':{
  1459.       elbow2Add();
  1460.       i++;
  1461.     }
  1462.     break;
  1463.   case 'Q':{
  1464.       elbow2Subtract();
  1465.       i++;
  1466.     }
  1467.     break;
  1468.   case 'S':{
  1469.       elbow1Add();
  1470.       i++;
  1471.     }
  1472.     break;
  1473.   case 'W':{
  1474.       elbow1Subtract();
  1475.       i++;
  1476.     }
  1477.     break;
  1478.     /* end of arm control functions */
  1479.  
  1480.     /* start of torso control functions */
  1481.   case 'd':{
  1482.       RotateAdd();
  1483.       i++;
  1484.     }
  1485.     break;
  1486.   case 'g':{
  1487.       RotateSubtract();
  1488.       i++;
  1489.     }
  1490.     break;
  1491.   case 'r':{
  1492.       MechTiltAdd();
  1493.       i++;
  1494.     }
  1495.     break;
  1496.   case 'f':{
  1497.       MechTiltSubtract();
  1498.       i++;
  1499.     }
  1500.     break;
  1501.     /* end of torso control functions */
  1502.  
  1503.     /* start of leg control functions */
  1504.   case 'h':{
  1505.       RaiseLeg2Forward();
  1506.       i++;
  1507.     }
  1508.     break;
  1509.   case 'y':{
  1510.       LowerLeg2Backwards();
  1511.       i++;
  1512.     }
  1513.     break;
  1514.   case 'Y':{
  1515.       RaiseLeg2Outwards();
  1516.       i++;
  1517.     }
  1518.     break;
  1519.   case 'H':{
  1520.       LowerLeg2Inwards();
  1521.       i++;
  1522.     }
  1523.     break;
  1524.  
  1525.   case 'j':{
  1526.       RaiseLeg1Forward();
  1527.       i++;
  1528.     }
  1529.     break;
  1530.   case 'u':{
  1531.       LowerLeg1Backwards();
  1532.       i++;
  1533.     }
  1534.     break;
  1535.   case 'U':{
  1536.       RaiseLeg1Outwards();
  1537.       i++;
  1538.     }
  1539.     break;
  1540.   case 'J':{
  1541.       LowerLeg1Inwards();
  1542.       i++;
  1543.     }
  1544.     break;
  1545.  
  1546.   case 'N':{
  1547.       Heel2Add();
  1548.       i++;
  1549.     }
  1550.     break;
  1551.   case 'n':{
  1552.       Heel2Subtract();
  1553.       i++;
  1554.     }
  1555.     break;
  1556.   case 'M':{
  1557.       Heel1Add();
  1558.       i++;
  1559.     }
  1560.     break;
  1561.   case 'm':{
  1562.       Heel1Subtract();
  1563.       i++;
  1564.     }
  1565.     break;
  1566.  
  1567.   case 'k':{
  1568.       Ankle2Add();
  1569.       i++;
  1570.     }
  1571.     break;
  1572.   case 'K':{
  1573.       Ankle2Subtract();
  1574.       i++;
  1575.     }
  1576.     break;
  1577.   case 'l':{
  1578.       Ankle1Add();
  1579.       i++;
  1580.     }
  1581.     break;
  1582.   case 'L':{
  1583.       Ankle1Subtract();
  1584.       i++;
  1585.     }
  1586.     break;
  1587.     /* end of leg control functions */
  1588.  
  1589.     /* start of light source position functions */
  1590.   case 'p':{
  1591.       LightTurnRight();
  1592.       i++;
  1593.     }
  1594.     break;
  1595.   case 'i':{
  1596.       LightTurnLeft();
  1597.       i++;
  1598.     }
  1599.     break;
  1600.   case 'o':{
  1601.       LightForwards();
  1602.       i++;
  1603.     }
  1604.     break;
  1605.   case '9':{
  1606.       LightBackwards();
  1607.       i++;
  1608.     }
  1609.     break;
  1610.     /* end of light source position functions */
  1611.   }
  1612.   if (i)
  1613.     glutPostRedisplay();
  1614. }
  1615.  
  1616. #endif
  1617.  
  1618. #ifdef GLUT_SPEC
  1619. void
  1620. special(int key, int x, int y)
  1621. {
  1622.  
  1623.   int i = 0;
  1624.  
  1625.   switch (key) {
  1626.     /* start of view position functions */
  1627.   case GLUT_KEY_RIGHT:{
  1628.       TurnRight();
  1629.       i++;
  1630.     }
  1631.     break;
  1632.   case GLUT_KEY_LEFT:{
  1633.       TurnLeft();
  1634.       i++;
  1635.     }
  1636.     break;
  1637.   case GLUT_KEY_DOWN:{
  1638.       TurnForwards();
  1639.       i++;
  1640.     }
  1641.     break;
  1642.   case GLUT_KEY_UP:{
  1643.       TurnBackwards();
  1644.       i++;
  1645.     }
  1646.     break;
  1647.     /* end of view postions functions */
  1648.     /* start of miseclleneous functions */
  1649.   case GLUT_KEY_PAGE_UP:{
  1650.       FireCannon();
  1651.       i++;
  1652.     }
  1653.     break;
  1654.     /* end of miscelleneous functions */
  1655.   }
  1656.   if (i)
  1657.     glutPostRedisplay();
  1658. }
  1659.  
  1660. #endif
  1661. #endif
  1662. void
  1663. menu_select(int mode)
  1664. {
  1665.   switch (mode) {
  1666. #ifdef ANIMATION
  1667.   case 1:
  1668.     glutIdleFunc(animation);
  1669.     break;
  1670. #endif
  1671.   case 2:
  1672.     glutIdleFunc(NULL);
  1673.     break;
  1674.   case 3:
  1675.     Toggle();
  1676.     glutPostRedisplay();
  1677.     break;
  1678.   case 4:
  1679.     exit(EXIT_SUCCESS);
  1680.   }
  1681. }
  1682.  
  1683. void
  1684. null_select(int mode)
  1685. {
  1686. }
  1687.  
  1688. void
  1689. glutMenu(void)
  1690. {
  1691.  
  1692.   int glut_menu[13];
  1693.  
  1694.   glut_menu[5] = glutCreateMenu(null_select);
  1695.   glutAddMenuEntry("forward       : q,w", 0);
  1696.   glutAddMenuEntry("backwards     : a,s", 0);
  1697.   glutAddMenuEntry("outwards      : z,x", 0);
  1698.   glutAddMenuEntry("inwards       : Z,X", 0);
  1699.  
  1700.   glut_menu[6] = glutCreateMenu(null_select);
  1701.   glutAddMenuEntry("upwards       : Q,W", 0);
  1702.   glutAddMenuEntry("downwards     : A,S", 0);
  1703.   glutAddMenuEntry("outwards      : 1,2", 0);
  1704.   glutAddMenuEntry("inwards       : 3,4", 0);
  1705.  
  1706.   glut_menu[1] = glutCreateMenu(null_select);
  1707.   glutAddMenuEntry(" : Page_up", 0);
  1708.  
  1709.   glut_menu[8] = glutCreateMenu(null_select);
  1710.   glutAddMenuEntry("forward       : y,u", 0);
  1711.   glutAddMenuEntry("backwards     : h.j", 0);
  1712.   glutAddMenuEntry("outwards      : Y,U", 0);
  1713.   glutAddMenuEntry("inwards       : H,J", 0);
  1714.  
  1715.   glut_menu[9] = glutCreateMenu(null_select);
  1716.   glutAddMenuEntry("forward       : n,m", 0);
  1717.   glutAddMenuEntry("backwards     : N,M", 0);
  1718.  
  1719.   glut_menu[9] = glutCreateMenu(null_select);
  1720.   glutAddMenuEntry("forward       : n,m", 0);
  1721.   glutAddMenuEntry("backwards     : N,M", 0);
  1722.  
  1723.   glut_menu[10] = glutCreateMenu(null_select);
  1724.   glutAddMenuEntry("toes up       : K,L", 0);
  1725.   glutAddMenuEntry("toes down     : k,l", 0);
  1726.  
  1727.   glut_menu[11] = glutCreateMenu(null_select);
  1728.   glutAddMenuEntry("right         : right arrow", 0);
  1729.   glutAddMenuEntry("left          : left arrow", 0);
  1730.   glutAddMenuEntry("down          : up arrow", 0);
  1731.   glutAddMenuEntry("up            : down arrow", 0);
  1732.  
  1733.   glut_menu[12] = glutCreateMenu(null_select);
  1734.   glutAddMenuEntry("right         : p", 0);
  1735.   glutAddMenuEntry("left          : i", 0);
  1736.   glutAddMenuEntry("up            : 9", 0);
  1737.   glutAddMenuEntry("down          : o", 0);
  1738.  
  1739.   glut_menu[4] = glutCreateMenu(NULL);
  1740.   glutAddSubMenu("at the shoulders? ", glut_menu[5]);
  1741.   glutAddSubMenu("at the elbows?", glut_menu[6]);
  1742.  
  1743.   glut_menu[7] = glutCreateMenu(NULL);
  1744.   glutAddSubMenu("at the hip? ", glut_menu[8]);
  1745.   glutAddSubMenu("at the knees?", glut_menu[9]);
  1746.   glutAddSubMenu("at the ankles? ", glut_menu[10]);
  1747.  
  1748.   glut_menu[2] = glutCreateMenu(null_select);
  1749.   glutAddMenuEntry("turn left    : d", 0);
  1750.   glutAddMenuEntry("turn right    : g", 0);
  1751.  
  1752.   glut_menu[3] = glutCreateMenu(null_select);
  1753.   glutAddMenuEntry("tilt backwards : f", 0);
  1754.   glutAddMenuEntry("tilt forwards  : r", 0);
  1755.  
  1756.   glut_menu[0] = glutCreateMenu(NULL);
  1757.   glutAddSubMenu("move the arms.. ", glut_menu[4]);
  1758.   glutAddSubMenu("fire the vulcan guns?", glut_menu[1]);
  1759.   glutAddSubMenu("move the legs.. ", glut_menu[7]);
  1760.   glutAddSubMenu("move the torso?", glut_menu[2]);
  1761.   glutAddSubMenu("move the hip?", glut_menu[3]);
  1762.   glutAddSubMenu("rotate the scene..", glut_menu[11]);
  1763. #ifdef MOVE_LIGHT
  1764.   glutAddSubMenu("rotate the light source..", glut_menu[12]);
  1765. #endif
  1766.  
  1767.   glutCreateMenu(menu_select);
  1768. #ifdef ANIMATION
  1769.   glutAddMenuEntry("Start Walk", 1);
  1770.   glutAddMenuEntry("Stop Walk", 2);
  1771. #endif
  1772.   glutAddMenuEntry("Toggle Wireframe", 3);
  1773.   glutAddSubMenu("How do I ..", glut_menu[0]);
  1774.   glutAddMenuEntry("Quit", 4);
  1775.   glutAttachMenu(GLUT_LEFT_BUTTON);
  1776.   glutAttachMenu(GLUT_RIGHT_BUTTON);
  1777. }
  1778.  
  1779. int
  1780. main(int argc, char **argv)
  1781. {
  1782. #ifdef GLUT
  1783.   /* start of glut windowing and control functions */
  1784.   glutInit(&argc, argv);
  1785.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
  1786.   glutInitWindowSize(800, 600);
  1787.   glutCreateWindow("glutmech: Vulcan Gunner");
  1788.   myinit();
  1789.   glutDisplayFunc(display);
  1790.   glutReshapeFunc(myReshape);
  1791. #ifdef GLUT_KEY
  1792.   glutKeyboardFunc(keyboard);
  1793. #endif
  1794. #ifdef GLUT_SPEC
  1795.   glutSpecialFunc(special);
  1796. #endif
  1797.   glutMenu();
  1798.   glutMainLoop();
  1799.   /* end of glut windowing and control functions */
  1800. #endif
  1801.   return 0;             /* ANSI C requires main to return int. */
  1802. }
  1803.